//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.yang.newcustomcuilian;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;

import com.yang.newcustomcuilian.listeners.SuitEffectListener;
import com.yang.newcustomcuilian.managers.Manager;
import com.yang.newcustomcuilian.movelevel.Config;
import com.yang.newcustomcuilian.variable.Variable;
import com.yang.newcustomcuilian.commander.Commander;
import com.yang.newcustomcuilian.language.Language;
import com.yang.newcustomcuilian.listeners.BListener;
import com.yang.newcustomcuilian.listeners.HealthFixListener;
import com.yang.newcustomcuilian.listeners.MainListener;
import com.yang.newcustomcuilian.loader.Loader;
import com.yang.newcustomcuilian.movelevel.MoveLevelInventory;
import com.yang.newcustomcuilian.newapi.NewAPI;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.java.JavaPlugin;

public final class NewCustomCuiLian extends JavaPlugin {
    public static int Max = 0;
    public static String ServerVersion = "";
    public static List<Material> arms = new ArrayList();
    public static List<Material> boots = new ArrayList();
    public static List<Material> chestplate = new ArrayList();
    public static Config config = new Config();
    public static Manager customCuilianManager = new Manager();
    public static List<Material> helmet = new ArrayList();
    public static List<Material> leggings = new ArrayList();
    public static List<String> localArms = new ArrayList();
    public static List<String> localBoots = new ArrayList();
    public static List<String> localChestplate = new ArrayList();
    public static List<String> localHelmet = new ArrayList();
    public static List<String> localLeggings = new ArrayList();
    public static HashMap<UUID, Double> playerSuitEffectHealthList = new HashMap();
    public static HashMap<UUID, Integer> playerSuitEffectList = new HashMap();
    public static List<String> powerArms = new ArrayList();
    public static List<String> powerBoots = new ArrayList();
    public static List<String> powerChestplate = new ArrayList();
    public static List<String> powerHelmet = new ArrayList();
    public static List<String> powerLeggings = new ArrayList();
    public static SuitEffectListener sel;
    public static Boolean usingDefaultPower;
    public static List<Variable> variables = new ArrayList();

    public NewCustomCuiLian() {
    }

    public void onEnable() {
        this.getLogger().info("插件已加载 By-banwang");

        try {
            ServerVersion = getServerVersion();
        } catch (NoSuchMethodException var3) {
            this.getLogger().info("服务器版本获取失败，插件无法启动");
            this.setEnabled(false);
        }

        this.saveDefaultConfig();
        this.reloadConfig();
        Server s = this.getServer();
        Loader.readVariables(this);
        Loader.readCuiLianItem(this);
        Loader.readItem(this);
        Loader.readYml(this);
        Language.loadLanguage(this);
        config.load(this);
        s.getPluginManager().registerEvents(new BListener(), this);
        s.getPluginManager().registerEvents(new MoveLevelInventory(), this);
        s.getPluginManager().registerEvents(new HealthFixListener(), this);
        if (usingDefaultPower) {
            s.getPluginManager().registerEvents(new MainListener(), this);
        }

        s.getPluginCommand("cuilian").setExecutor(new Commander());
        reloadRecipe();
        SuitEffectListener suitEffectListener = new SuitEffectListener();
        sel = suitEffectListener;
        suitEffectListener.runTaskTimer(this, 20L, 2L);
    }

    public void onDisable() {
        try {
            Iterator var1 = playerSuitEffectList.keySet().iterator();

            while(var1.hasNext()) {
                UUID id = (UUID)var1.next();
                LivingEntity le = NewAPI.getLivingEntityByEntityId(id);
                if (le != null) {
                    NewAPI.setMaxHealth(le, (Double)playerSuitEffectHealthList.get(le.getUniqueId()));
                    playerSuitEffectHealthList.remove(le.getUniqueId());
                    playerSuitEffectList.remove(le.getUniqueId());
                }
            }
        } catch (ConcurrentModificationException var4) {
        }

    }

    public static void reloadRecipe() {
        for(int i = 0; i < customCuilianManager.ItemList.size(); ++i) {
            Material material = (Material)customCuilianManager.ItemList.get(i);
            if(material == null) continue;
            System.out.println("读取到物品: " + material.name());
            FurnaceRecipe Furnace = new FurnaceRecipe(
                new ItemStack(material), 
                material
            );

            for(int j = 0; j <= material.getMaxDurability(); ++j) {
                Furnace.setInput(material, j);
                try {
                    getPlugin(NewCustomCuiLian.class).getServer().addRecipe(Furnace);
                } catch (IllegalStateException var4) {
                }
            }
        }
    }

    public static String getServerVersion() throws NoSuchMethodException {
        Method[] var0 = PlayerInventory.class.getDeclaredMethods();
        int var1 = var0.length;

        for(int var2 = 0; var2 < var1; ++var2) {
            Method e = var0[var2];
            if (e.toGenericString().contains("getItemInMainHand")) {
                return "1.9+";
            }
        }

        if (Material.getMaterial("SLIME_BLOCK") != null) {
            return "1.8";
        } else {
            return "1.7";
        }
    }
}
